//
//  CRCommentTextField.m
//  CRChatRoom
//
//  Created by lanou3g on 15/11/25.
//  Copyright © 2015年 SecondGroup. All rights reserved.
//

#import "CRCommentTextField.h"

@interface CRCommentTextField ()

@property (nonatomic, strong) UIButton *bt;

@property (nonatomic, strong) UIImageView *dividerImage;

@end


@implementation CRCommentTextField

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {

        self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"textfieldbg"]];
                                
        
        // 添加按钮
        self.bt = [[UIButton alloc] init];
        [self.bt addTarget:self action:@selector(clickbutton:andTextField:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.bt];
        [self.bt setImage:[UIImage imageNamed:@"iconfont-xiaolian"] forState:UIControlStateNormal];
        
        // 添加分割线
        self.dividerImage = [[UIImageView alloc] init];
        self.dividerImage.image = [UIImage imageNamed:@"iconfont-shuxian"];
        [self addSubview:self.dividerImage];
        
        
    }
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    CGFloat width = self.frame.size.width;
    CGFloat W = 30;
    CGFloat X = width - W;
    self.bt.frame = CGRectMake(X, 0, W, W);
    
    self.dividerImage.frame = CGRectMake(X-10, 0, 5, W);
    
    
    
}

#pragma mark - 点击了按钮触发的方法
- (void)clickbutton:(UIButton *)button andTextField:(UITextField *)textField
{
    if ([self.commentDelegate respondsToSelector:@selector(commentTextFieldDidClickButton:andtextField:)]) {
        [self.commentDelegate commentTextFieldDidClickButton:button andtextField:self];
    }
    
}

@end













